home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.022.AutoLaunch / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  5.6 KB  |  271 lines  |  [TEXT/MPS ]

  1. /**********************************************************************
  2. *
  3. * autolaunch menu.c -- Version 3.0
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1988-1990
  7. * All Rights Reserved.
  8. *
  9. * Written by Eric Soldan.
  10. *
  11. * Developer Technical Support Apple II Sample Code
  12. *
  13. * This file contains the code which implements menus in the
  14. * autolaunch program.
  15. *
  16. **********************************************************************/
  17.  
  18. #include <types.h>
  19. #include <window.h>
  20. #include <event.h>
  21. #include <menu.h>
  22. #include <desk.h>
  23. #include <intmath.h>
  24. #include <resources.h>
  25. #include <stdfile.h>
  26.  
  27. #include "autolaunch.h"
  28.  
  29. void    appSetMenus();
  30. void    doMenuCommand();
  31. void    chooseTriggerFile();
  32. void    chooseTargetFile();
  33. void    invalOneCtl();
  34.  
  35. /**********************************************************************/
  36.  
  37. void    doQuitItem()
  38. {
  39.     quitFlag++;
  40. }
  41.  
  42. /**********************************************************************/
  43.  
  44. void            setMItem(id, flag)
  45. unsigned int    id, flag;
  46. {
  47.     if (flag) EnableMItem(id);
  48.     else      DisableMItem(id);
  49. }
  50.  
  51. /**********************************************************************/
  52.  
  53. void    doAboutItem()
  54. {
  55.     WindowPtr        wptr, keepPort;
  56.     unsigned long    id;
  57.     unsigned int    item;
  58.  
  59.     zapLocals();
  60.  
  61.     keepPort = GetPort();
  62.  
  63.     wptr = NewWindow2(NULL, NULL, NULL, NULL, 2, AboutWindowID, rWindParam1);
  64.     if (!_toolErr) {
  65.         aboutWindow = wptr;
  66.         for (;;) {
  67.             doNetCheck(0);
  68.             if (quitFlag) break;
  69.  
  70.             id = fakeModalDialog(&event, NULL, NULL, NULL,
  71.                 fmdMenuSelect+
  72.                 fmdMenuKey+
  73.                 fmdDeskAcc+
  74.                 fmdUpdateAll
  75.             );
  76.             item = id;                                /* Get lo-word. */
  77.             if (id & 0x80000000L) {                    /* If menu command... */
  78.                 if (item == 255) {
  79.                     HiliteMenu(0, FileMenuID);        /* Nobody else is going to.          */
  80.                     break;                            /* If close, close the about box. */
  81.                 }
  82.                 doMenuCommand(id);
  83.                 if (quitFlag) break;
  84.             }
  85.             else if (item == 1) break;                /* ...else handle controls. */
  86.         }
  87.     
  88.         SetPort(keepPort);
  89.         CloseWindow(wptr);
  90.         aboutWindow = NULL;
  91.         appSetMenus();
  92.     }
  93. }
  94.  
  95. /**********************************************************************/
  96.  
  97. void            doMenuCommand(id)
  98. unsigned long    id;
  99. {
  100.     unsigned int    menuNum, itemNum;
  101.  
  102.     zapLocals();
  103.  
  104.     menuNum = HiWord(id) & 0x7FFF;
  105.     itemNum = LoWord(id);
  106.  
  107.     switch (itemNum) {
  108.  
  109.         case AboutItem:
  110.             HiliteMenu(0, AppleMenuID);        /* Unhighlight the menu title first. */
  111.             menuNum = 0;                    /* Don't unhilight again. */
  112.             doAboutItem();
  113.             break;
  114.  
  115.         case QuitItem:
  116.             doQuitItem();
  117.             break;
  118.  
  119.         case ChooseTriggerItem:
  120.             chooseTriggerFile();
  121.             break;
  122.  
  123.         case ChooseTargetItem:
  124.             chooseTargetFile();
  125.             break;
  126.  
  127.         case SaveLaunchItem:
  128.             saveLaunchInfo();
  129.             break;
  130.  
  131.         case UndoItem:
  132.         case CutItem:
  133.         case CopyItem:
  134.         case PasteItem:
  135.         case ClearItem:
  136.         case CloseItem:
  137.             break;
  138.     }
  139.  
  140.     if (menuNum) HiliteMenu(0, menuNum);        /* Unhighlight the menu title. */
  141. }
  142.  
  143. /**********************************************************************/
  144.  
  145. void    setupMenus()
  146. {
  147.     /* Procedure to install our menu titles and their items in the system menu
  148.     ** bar and to redraw it so we can see them.
  149.     */
  150.  
  151.     SetSysBar(NewMenuBar2(refIsResource, 0x0001L, NULL));
  152.     SetMenuBar(NULL);
  153.     
  154.     FixAppleMenu(AppleMenuID);                /* Add DAs to apple menu     */
  155.     FixMenuBar();                            /* Set sizes of menus         */
  156.     DrawMenuBar();                            /* ...and draw the menu bar! */
  157.  
  158.     DisableMItem(UndoItem);
  159.     fmdSetMenuProc(appSetMenus);
  160. }
  161.  
  162. /**********************************************************************/
  163.  
  164. void    appSetMenus()
  165. {
  166.     unsigned int    about, frontIsDA, i;
  167.  
  168.     zapLocals();
  169.  
  170.     about = frontIsDA = 0;
  171.  
  172.     if (aboutWindow) about++;
  173.     if (GetWKind(FrontWindow()) & 0x8000) frontIsDA++;
  174.  
  175.     setMItem(AboutItem, !about);
  176.         /* If about isn't already open, then allow it to be opened. */
  177.  
  178.     setMItem(CloseItem, i = (about | frontIsDA));
  179.         /* If we have an about box or DA, then allow close. */
  180.  
  181.     setMItem(ChooseTriggerItem, i = !i);
  182.     setMItem(ChooseTargetItem, i);
  183.  
  184.     if (!frontIsDA) DisableMItem(UndoItem);
  185. }
  186.  
  187. /**********************************************************************/
  188.  
  189. void    chooseTriggerFile()
  190. {
  191.     SFReplyRec2        myReply;
  192.  
  193.     myReply.nameRefDesc = myReply.pathRefDesc = refIsNewHandle;
  194.     SFGetFile2(                    /* Do an incredibly ordinary SFGetFile2. */
  195.         80, 32,
  196.         refIsPointer,
  197.         "\pChoose a Trigger File",
  198.         NULL,
  199.         NULL,
  200.         &myReply
  201.     );
  202.  
  203.     if (myReply.good) {            /* User did pick something... */
  204.         BlockMove(*(char **)myReply.pathRef + 2, launch.triggerPath, 514L);
  205.         DisposeHandle(myReply.pathRef);
  206.  
  207.         BlockMove(*(char **)myReply.nameRef + 2, launch.triggerName, 34L);
  208.         DisposeHandle(myReply.nameRef);
  209.  
  210.         updateControls();
  211.         invalOneCtl(GetCtlHandleFromID(mainWindow, AppTriggerData));
  212.  
  213.         getFileInfo();
  214.         launch.dates[0] = launch.dates[2];
  215.         launch.dates[1] = launch.dates[3];
  216.     }
  217. }
  218.  
  219. /**********************************************************************/
  220.  
  221. void    chooseTargetFile()
  222. {
  223.     SFReplyRec2        myReply;
  224.  
  225.     myReply.nameRefDesc = myReply.pathRefDesc = refIsNewHandle;
  226.     SFGetFile2(                    /* Do an incredibly ordinary SFGetFile2. */
  227.         80, 32,
  228.         refIsPointer,
  229.         "\pChoose a Target Launch File",
  230.         NULL,
  231.         NULL,
  232.         &myReply
  233.     );
  234.  
  235.     if (myReply.good) {            /* User did pick something... */
  236.         BlockMove(*(char **)myReply.pathRef + 2, launch.targetPath, 514L);
  237.         DisposeHandle(myReply.pathRef);
  238.  
  239.         BlockMove(*(char **)myReply.nameRef + 2, launch.targetName, 34L);
  240.         DisposeHandle(myReply.nameRef);
  241.  
  242.         updateControls();
  243.         invalOneCtl(GetCtlHandleFromID(mainWindow, AppTargetData));
  244.     }
  245. }
  246.  
  247. /**********************************************************************/
  248.  
  249. void        invalOneCtl(ctlHndl)
  250. CtlRecHndl    ctlHndl;
  251. {
  252.     GrafPortPtr    keepPort;
  253.     CtlRecPtr    ctlPtr;
  254.     Rect        rct, *rctPtr;
  255.  
  256.     ctlPtr = *ctlHndl;
  257.  
  258.     keepPort = GetPort();
  259.     SetPort(ctlPtr->ctlOwner);
  260.     
  261.     rctPtr = &(ctlPtr->ctlRect);
  262.     rct.v1 = rctPtr->v1;
  263.     rct.h1 = rctPtr->h1;
  264.     rct.v2 = rctPtr->v2;
  265.     rct.h2 = rctPtr->h2;
  266.  
  267.     InvalRect(&rct);
  268.     SetPort(keepPort);
  269. }
  270.  
  271.